package com.martin.dms.services.util;

/**
 * Utility class for the services' needs.
 * 
 * @author mtsvetkov
 */
public class ServicesUtil {

    private static final String STAR_CHAR = "*";
    public static final String REGEX_STAR = ".*";

    /**
     * Private constructor to prevent instantiation.
     */
    private ServicesUtil() {
    }

    /**
     * Parses filter string to a regex.
     * 
     * @param filter to parse.
     * @return the parsed filter.
     */
    public static String parseFilterString(String filter) {
        filter = filter.trim().toLowerCase();
        if (filter == null || filter.length() == 0) {
            filter = STAR_CHAR;
        }
        if (!filter.startsWith(STAR_CHAR)) {
            filter = STAR_CHAR + filter;
        }
        if (!filter.endsWith(STAR_CHAR)) {
            filter = filter + STAR_CHAR;
        }
        filter = filter.replace(STAR_CHAR, REGEX_STAR);
        return filter;
    }
}
